//package com.qiaofang.common.utils;
//
//import com.aliyun.oss.ClientException;
//import com.aliyun.oss.OSSClient;
//import com.aliyun.oss.OSSException;
//import com.aliyun.oss.model.ObjectMetadata;
//import com.aliyun.oss.model.PutObjectResult;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.io.InputStream;
//
///**
// * <p>
// * OSS上传工具类
// * </p>
// */
//public class OssClientUtil {
//
//	private static final Logger logger = LoggerFactory.getLogger(OssClientUtil.class);
//
//	private static final String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
//	private static final String accessKeyId = "LTAIVYLTh40QT6wt";
//	private static final String secretAccessKey = "7xrO0bLqoxc7WZao3j3qyQkBmaU8iF";
//	private static final String bucketName = "qf-fanke";
//	private static final String aliyunpath = "https://qf-fanke.oss-cn-hangzhou.aliyuncs.com";
//
//
//	/**
//	 *  上传文件
//	 * @throws OSSException
//	 * @throws ClientException
//	 * @throws FileNotFoundException
//	 */
//	public static String uploadFile(String fileName, InputStream is)
//			throws OSSException, ClientException, IOException {
//
//		OSSClient ossClient = new OSSClient(endpoint, accessKeyId, secretAccessKey);
//
//		//创建上传Object的Metadata
//		ObjectMetadata objectMetadata = new ObjectMetadata();
//		objectMetadata.setContentLength(is.available());
//		objectMetadata.setCacheControl("no-cache");
//		objectMetadata.setHeader("Pragma", "no-cache");
//		objectMetadata.setContentType(getcontentType(fileName.substring(fileName.lastIndexOf("."))));
//		objectMetadata.setContentDisposition("inline;filename=" + fileName);
//		PutObjectResult result =  ossClient.putObject(bucketName, fileName, is, objectMetadata);
//		ossClient.shutdown();
//		if(StringUtils.isNotBlank(result.getETag())){
//			return aliyunpath + "/" + fileName;
//		}
//		return "";
//	}
//
//
//	/**
//	 * Description: 判断OSS服务文件上传时文件的contentType
//	 *
//	 * @param FilenameExtension 文件后缀
//	 * @return String
//	 */
//	public static String getcontentType(String FilenameExtension) {
//		if (FilenameExtension.equalsIgnoreCase(".bmp")) {
//			return "image/bmp";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".gif")) {
//			return "image/gif";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".jpeg") ||
//				FilenameExtension.equalsIgnoreCase(".jpg") ||
//				FilenameExtension.equalsIgnoreCase(".png")) {
//			return "image/jpeg";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".html")) {
//			return "text/html";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".txt")) {
//			return "text/plain";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".vsd")) {
//			return "application/vnd.visio";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".pptx") ||
//				FilenameExtension.equalsIgnoreCase(".ppt")) {
//			return "application/vnd.ms-powerpoint";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".docx") ||
//				FilenameExtension.equalsIgnoreCase(".doc")) {
//			return "application/msword";
//		}
//		if (FilenameExtension.equalsIgnoreCase(".xml")) {
//			return "text/xml";
//		}
//        if (FilenameExtension.equalsIgnoreCase(".mp3")) {
//            //return "application/octet-stream";
//            return "audio/mpeg";
//        }
//        if (FilenameExtension.equalsIgnoreCase(".m4a")) {
//            return "video/mpeg4";
//        }
//		return "image/jpeg";
//	}
//}